package com.example.xm.controller;

import com.example.xm.entity.Fenlei;
import com.example.xm.service.IFenleiService;
import com.example.xm.web.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fenlei")
public class FenleiController {
    @Autowired
    IFenleiService shipinfenleiService;
    @PostMapping("/add")
    public Result reg(@RequestBody Fenlei gonggao){
        System.out.println("user"+gonggao);
        shipinfenleiService.reg(gonggao);
        return Result.success();
    }
    @PostMapping("/update")
    public Result update(@RequestBody Fenlei gonggao){
//        System.out.println(account+"=========="+password);
        shipinfenleiService.update(gonggao);
        return Result.success();

    }
    @GetMapping("/list")
    public Result list(String name,Integer page,Integer size,Integer type){
        PageInfo<Fenlei> pageInfo= shipinfenleiService.list(name,page,size,type);
        return Result.success(pageInfo);
    }
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable String ids){
        String[] split = ids.split(",");
        int[] intArray = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            intArray[i] = Integer.parseInt(split[i]);
        }
        shipinfenleiService.delete(intArray);
        return Result.success();
    }
}
